package ru.payment.wm.impl;

import org.dom4j.Element;
import ru.payment.wm.Directory;
import ru.payment.wm.impl.response.DirectoryObjectImpl;

import java.util.List;

/**
 *
 * User: sergey
 * Date: 23.04.2009
 * Time: 15:58:39
 *
 */
public class DirectoryParser extends AbstractResponseParser<Directory, Element> {

  public void parse(Element e, Directory dir) throws ProtocolException {
    if (e == null) {
      return;
    }

    List<Element> el = e.elements("ctype");
    for (Element ei : el) {
      String szId = ei.attributeValue("id");
      int id = Integer.parseInt(szId);
      dir.getPersonTypeList().add(new DirectoryObjectImpl(id, asString(ei, "")));
    }

    el = e.elements("jstatus");
    for (Element ei : el) {
      String szId = ei.attributeValue("id");
      int id = Integer.parseInt(szId);
      dir.getJuridicalStatusList().add(new DirectoryObjectImpl(id, asString(ei, "")));
    }

    el = e.elements("tid");
    for (Element ei : el) {
      String szId = ei.attributeValue("id");
      int id = Integer.parseInt(szId);
      dir.getAttestatTypeList().add(new DirectoryObjectImpl(id, asString(ei, "")));
    }

  }

}
